home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / battmonitor ƒ / GetVoltage.c < prev   
Encoding:
C/C++ Source or Header  |  1992-06-06  |  595 b   |  34 lines  |  [TEXT/MPS ]

  1. #include <Power.h>
  2. #include <GestaltEqu.h>
  3.  
  4. pascal Boolean PluggedIn (void);
  5. pascal short GETVOLTAGE (void);
  6.  
  7. pascal Boolean PluggedIn (void)
  8. {
  9. Boolean chargerConnected = true;    // desktop macs got a 'charger' :)
  10. Byte status, power;
  11. OSErr errorCode = noErr;
  12. long response;
  13.  
  14. errorCode = Gestalt(gestaltPowerMgrAttr, &response);
  15. if (response & 1)
  16.     {
  17.     BatteryStatus(&status, &power);
  18.     chargerConnected = (status & 0x01);
  19.     }
  20.  
  21. return chargerConnected;
  22. }
  23.  
  24. pascal short GETVOLTAGE (void)
  25. {
  26. short voltage;
  27. Byte status, power;
  28.  
  29. BatteryStatus(&status, &power);
  30. voltage = ((short)power);
  31.  
  32. return voltage;
  33. }
  34.